import { Application } from 'egg';

export default (app: Application) => {
  const { controller, router, middleware } = app;
  const authorization = middleware.authorization();

  router.post('/api/uploadImage', controller.base.uploadImage);

  router.post('/api/login', controller.user.login);
  router.post('/api/regist', controller.user.regist);

  router.get('/api/users', controller.user.index);
  router.get('/api/userInfo', authorization, controller.user.getLoginUserBasicInfo);
  router.get('/api/users/info/batch', controller.user.batchGetUserInfo);
  //关注用户
  router.put('/api/users/:userId/follow', authorization, controller.user.toggleFollow);

  router.put('/api/updateUser', authorization, controller.user.update);
  router.put('/api/updateAvatar', authorization, controller.user.updateAvatar);

  router.get('/api/articles', controller.article.index);
  router.get('/api/articles/:articleId', controller.article.getArticle);
  router.get('/api/articles/:articleId/front', controller.article.getFrontArticle);
  router.post('/api/articles/save', authorization, controller.article.save);
  router.put('/api/articles/:articleId/like', authorization, controller.article.toggleLike);
  router.get('/api/articles/:articleId/likeUsers', controller.article.getLikeUsers);
  router.put('/api/articles/:articleId/collect', authorization, controller.article.toggleCollect);

  router.get('/api/categoriesAndTags', controller.article.getCategoriesAndTags);

  router.post('/api/draft/save', authorization, controller.draft.saveDraft);
  router.get('/api/drafts', authorization, controller.draft.getMeDrafts);

  // 获取文章评论
  router.get('/api/articles/:articleId/comments', controller.comment.getCommentsByArticleId);

  router.post('/api/comments/save', authorization, controller.comment.save);
  router.put('/api/comments/:commentId/like', authorization, controller.comment.toggleLike);
  router.get('/api/comments/:commentId/likeUsers', controller.comment.getLikeUsers);

  // router.get('/api/test/:userId', controller.user.getTest);

};
